<?php


function smarty_function_addThis($params, &$smarty) {
	if (isset($params['username'])) {
		$username = $params['username'];
	} else if (Config::Get('ADDTHIS_USERNAME')) {
		$username = Config::Get('ADDTHIS_USERNAME');
	} else {
		trigger_error("No username for addThis, define var ADDTHIS_USERNAME in param config.");
	}

	$html = '
	<!-- AddThis Button BEGIN -->
		<div class="addthis_toolbox">
		<a class="addthis_button_facebook"></a>
		<a class="addthis_button_blip"></a>
		<a class="addthis_button_email"></a>
		<a class="addthis_button_twitter"></a><a style="" href="http://www.addthis.com/bookmark.php?v=250&amp;username=getak" class="addthis_button_compact">&nbsp;Udostępnij</a>
		</div>
		<script type="text/javascript">
		var addthis_config ={
			ui_click: true,
			ui_language: "pl"
		};';

	$share = array();

	foreach ($params as $key => $value) {
		if (substr($key, 0, 6) == 'share_') {
			$share[substr($key, 6)] = $value;
		}
	}
	
	if (sizeof($share)) {
		$html .= 'var addthis_share = {';

		$htmla = array();
		
		foreach ($share as $k => $v) {
			$htmla[] = $k . ': "' . $v . '"';
		};

		$html .= implode("\n", $htmla);
	}

	$html .= '
		</script>
		<script type="text/javascript" src="http://s7.addthis.com/js/250/addthis_widget.js#username=' . $username . '"></script>
	<!-- AddThis Button END -->
	';

	return $html;
}
?>